package character;

import config.Config;
import sprite.Transform;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;

public abstract class AttackAbleObject extends GameObject{
	private Transform _transform;

	private int _cx1;
	private int _cx2;
	private int _cy1;
	private int _cy2;

	private boolean _hitting = false;
	private int _strength;

	public AttackAbleObject(Transform trans,  int strength,
                            int hurt_x, int hurt_y, int hurtscale_x, int hurtscale_y, int hitoffset_x1,
                            int hitoffset_y1, int hitoffset_x2, int hitoffset_y2) {
		super(trans,hurt_x,hurt_y,hurtscale_x, hurtscale_y);
		_strength = strength;
		_transform = trans;
		this.setHitBoxOffsets(hitoffset_x1,hitoffset_y1,hitoffset_x2,hitoffset_y2);
	}

	public Shape getHitBox(){
		AffineTransform as = new AffineTransform();
		as.setTransform(_transform.getTransform());
		return as.createTransformedShape(new Rectangle(_cx1,_cy1,_cx2,_cy2));
	}
	public void setHitBoxOffsets(int x1,int y1, int x2, int y2){
		_cx1 = x1;
		_cx2 = x2;
		_cy1 = y1;
		_cy2 = y2;
	}

	public void setStrength(int strength){
		_strength = strength;
	}

	public int getStrength(){
		return _strength;
	}


	public boolean isHitting(){
		return _hitting;
	}

	public void setHitting(boolean hit){
		_hitting = hit;
	}

	public boolean hasHitBoxCollide(GameObject other){
		Area areaA = new Area(getHitBox());
		areaA.intersect(new Area(other.getHurtBox()));

		return !areaA.isEmpty() && Math.abs(getZ()-other.getZ())< Config.Z_FIGHT_DIST;
	}


}
